home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / MoofWars / Tim's Libraries / Error Macros.h < prev    next >
Encoding:
Text File  |  2000-09-28  |  1.9 KB  |  57 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Error Macros.h
  3.  
  4.     Contains:    These macros can be used to implement nice error handling within a function.
  5.                 Essentially, all errors jump to an error handler at the end of the function, 
  6.                 which should cleanup  any leftovers and return the appropriate error result.
  7.  
  8.                 Note that the error handlers take a message string.  This should be a good
  9.                 indication of the actual error, and it will appear when debugging is turned
  10.                 on.
  11.     
  12.                 Note that any additional sanity checking code can be added to any function 
  13.                 by using
  14.     
  15.                     #if qDebugging
  16.                           // do additional sanity checking here.
  17.                     #endif
  18.     
  19.                 For example, this could be used to check the internal validity of an object
  20.                 before taking an action.
  21.  
  22.     Written by: Timothy Carroll    
  23.  
  24.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  25.  
  26.                 You may incorporate this Apple sample source code into your program(s) without
  27.                 restriction. This Apple sample source code has been provided "AS IS" and the
  28.                 responsibility for its operation is yours. You are not permitted to redistribute
  29.                 this Apple sample source code as "Apple sample source code" after having made
  30.                 changes. If you're going to re-distribute the source, we require that you make
  31.                 it clear in the source that the code was descended from Apple sample source
  32.                 code, but that you've made changes.
  33.  
  34.     Change History (most recent first):
  35.                 7/2/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  36.                 
  37.  
  38. */
  39. // App may want to override qDebugging
  40. #include "AppConditionals.h"
  41.  
  42. #pragma once
  43.  
  44. #ifndef qDebugging
  45.     #define qDebugging 0
  46. #endif
  47.  
  48. #if qDebugging
  49.     #define SIGNAL_ERROR(msg)        {DebugStr(msg); goto error;}
  50. #else
  51.     #define SIGNAL_ERROR(msg)        {goto error;}
  52. #endif
  53.  
  54. #define FAIL_NIL(y,msg)            if (y == NULL) SIGNAL_ERROR(msg)
  55. #define FAIL_OSERR(y,msg)        if (y != noErr) SIGNAL_ERROR(msg)
  56. #define FAIL_FALSE(y,msg)        if (!y) SIGNAL_ERROR(msg)
  57.